// Purpuse : This page is use for add and list all posted message.
//           In this page we are using two user controls doctormenu and Postmessage usercontrols,
//           Post message user controls will display for authenticate users
// Date    : 27 August,2007
// Author  : Vinayak Singh Rathore
 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
public partial class DentistViewMessage : System.Web.UI.Page
{
   protected int DentistId; // for hold dentist Id
    protected Manager manager;
    protected void Page_Load(object sender, EventArgs e)
    {
        // check, user come here as authenticated
        if (Request.QueryString["id"] != null)
        {
            try
            {
                DentistId = Convert.ToInt32(Request.QueryString["id"]);
                PostMessage1.TopicId = DentistId;//set blog id value in TopicId property
            }
            catch { }
        }
        if (!Page.IsPostBack)
        {
            BindGrid();
        }
        BindGrid();
    }

   
    protected override void Render(HtmlTextWriter writer)
    {
        if (Manager.GetPostBackControl(Page) == "btnSubmit")
        {
            BindGrid();
        }
        base.Render(writer);
    }

    /// <summary>
    ///  public void BindGrid()
    /// <remarks>this function is use for bind reapeater control</remarks>
    /// <author>Vinayak Singh Rathore 27, Aug 2007</author>
    /// </summary>
    public void BindGrid()
    {
        manager = new Manager(true,"ConnectionString");
        //Show doctor name and his/her email id in Label
        string SQLBlog = "SELECT (FName+' '+MName+' '+LName) AS Name FROM tbl_dentists WHERE id = " + DentistId;
        DataSet dsShowBlog = manager.ExecuteQuery(SQLBlog, "tbl_Topics");
        if (dsShowBlog.Tables[0].Rows.Count > 0)
        {
            lblBlogName.Text = dsShowBlog.Tables[0].Rows[0][0].ToString();
           // DentistId.Text = dsShowBlog.Tables[0].Rows[0][0].ToString();
        }
        
        string SQL = @"SELECT tbl_dentistMessage.Description AS msgDescription,tbl_dentistMessage.DateAdded AS msgDate,
                    case usertype when 1 then (SELECT 'Admin') 
                    when 3 then (SELECT nickname from tbl_users WHERE id=tbl_dentistMessage.userid)
                    when 2 then (SELECT FName from tbl_dentists WHERE id=tbl_dentistMessage.userid)
                    when 4 then (SELECT FName from tbl_doctors WHERE id=tbl_dentistMessage.userid) 
                    end AS postedName FROM  tbl_dentistMessage WHERE tbl_dentistMessage.DentistId = " + DentistId + "Order By  tbl_dentistMessage.DateAdded DESC";


        DataSet ds = manager.ExecuteQuery(SQL, "tbl_dentistMessage");
        if (ds.Tables[0].Rows.Count > 0)
        {
            grdDentistBlog.DataSource = ds.Tables[0];
            grdDentistBlog.DataBind();
            lblerr.Visible = false;
        }
        else
        {
            lblerr.Text = "<font color=red><b>No message posted currently !!!</b></font>";
            lblerr.Visible = true;
        }
    }
    
}
